<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link href="../static/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="../static/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="../static/css/animate.min.css" rel="stylesheet">
    <link href="../static/css/style.min.css?v=4.0.0" rel="stylesheet"><base target="_blank">
    <link rel="stylesheet" href="../static/css/plugins/popup/popup.css">
    <link rel="stylesheet" href="../static/css/login.css">
    <!--[if lt IE 8]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
    <!-- <script>if(window.top !== window.self){ window.top.location = window.location;}</script> -->
    <style>
       body{
         background-color: #2f4050!important;
       }
       .login-box h3{
         color: #000;
       }
       .loginscreen{
         background: #fff;
         border-radius: 10px;
         padding: 30px;
       }
    </style>
</head>

<body class="gray-bg">
    <div class="middle-box text-center loginscreen  animated fadeInDown">
        <div class="login-box">
            <h3><img src="../static/images/logo.jpg" style="width: 40px;height: 40px;" />  逗徕互娱后台管理系统</h3>
            <div>
                <div class="form-group">
                    <input type="text" class="form-control" name="username" placeholder="用户名">
                </div>
                <div class="form-group">
                    <input type="password" class="form-control" name="password" placeholder="密码">
                </div>
                <div class="form-group form-code">
                   <input type="text" class="form-control" name="code" placeholder="验证码" maxlength="5">
                   <a class="img-code" title="点击更换验证码"><image class="imgcode" src="" /></a>
                </div>
                <button class="btn btn-primary block full-width m-b">登 录</button>
                <!-- <p class="text-muted text-center"> <a href="login.html#"><small>忘记密码了？</small></a> | <a href="register.html">注册一个新账号</a>
                </p> -->
            </div>
        </div>
    </div>
    <script src="../static/js/jquery.min.js?v=2.1.4"></script>
    <script src="../static/js/plugins/popup/popup.js"></script>
    <script src="../static/js/http.js"></script>
    <script type="text/javascript">
      var rules = {
    		username: {
    			regExp: /^\s*$/g,
    			msg: '请输入用户名！'
    		},
//     		password: {
//     			regExp: /^(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/,
//     			msg: '请输入8-15位的密码'
//     		},
        code:{
          regExp:/^\s*$/g,
          msg:'请输入验证码'
        }
    	};

      // 表单验证
      function formValidate() {
         var username = $.trim($('input[name="username"]').val());
         var password = $.trim($('input[name="password"]').val());
         var code = $.trim($('input[name="code"]').val());
         var inputArr = ['username','password','code'];
         if(rules.username.regExp.test(username)){
            popup.tips(rules.username.msg,1000);
            return;
         }
//          if(!rules.password.regExp.test(password)){
//             popup.tips(rules.password.msg,1000);
//             return;
//          }
         if(!password){
			 popup.tips('请输入密码',1000);
			 return;
		 }
         if(rules.code.regExp.test(code)){
            popup.tips(rules.code.msg,1000);
            return;
         }
        return true;
      }

        $('.btn-primary').on('click',function(){
            var flag = formValidate();
            if(flag){//基本验证通过--提交表单
               var params = {
                 username:$.trim($('input[name="username"]').val()),
                 password:$.trim($('input[name="password"]').val()),
                 validateCode:$.trim($('input[name="code"]').val()),
                 rememberMe:false
               };
               _POST('/login',params).then(function(res){
                  //登录成功
				  if(res.msg=='请修改密码'){
					  location.href = '/system/user/password';
				  }else{
					  setTimeout(function(){
						 location.href="menu/index"
					  },500)				
				  }
//                   
               },function(fail){
                  popup.tips(fail.msg,1000);
				  //刷新验证码
				  $(".imgcode").attr("src", "/captcha/captchaImage?type=math&s=" + Math.random());
               })
              // window.location.href="index.html"
            }
        })

        //点击更换验证码
        $(".imgcode").attr("src", "/captcha/captchaImage?type=math&s=" + Math.random());
        $('.imgcode').click(function() {
      		var url = "/captcha/captchaImage?type=math&s=" + Math.random();
      		$(".imgcode").attr("src", url);
      	});
		
		history.pushState(null, null, document.URL);
        window.addEventListener('popstate', function () {
            history.pushState(null, null, document.URL);
        });
		
		
    </script>
</body>

</html>
